{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "class Solution:\n",
    "    def generate(self, numRows: int) -> [[int]]:\n",
    "        # Check the boundary\n",
    "        if numRows == 0:\n",
    "            return []\n",
    "        if numRows == 1:\n",
    "            return [[1]]\n",
    "        if numRows == 2:\n",
    "            return [[1],[1,1]]\n",
    "\n",
    "        nums = [[1],[1,1]]\n",
    "\n",
    "        for i in range(2, numRows):\n",
    "            layer = [1]*(i + 1)\n",
    "            for j in range(1, i):\n",
    "                layer[j] = nums[i-1][j-1] + nums[i-1][j]\n",
    "            nums.append(layer)\n",
    "        return nums"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "s = Solution()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[]\n",
      "[[1]]\n",
      "[[1], [1, 1]]\n",
      "[[1], [1, 1], [1, 2, 1]]\n",
      "[[1], [1, 1], [1, 2, 1], [1, 3, 3, 1]]\n",
      "[[1], [1, 1], [1, 2, 1], [1, 3, 3, 1], [1, 4, 6, 4, 1]]\n",
      "[[1], [1, 1], [1, 2, 1], [1, 3, 3, 1], [1, 4, 6, 4, 1], [1, 5, 10, 10, 5, 1]]\n",
      "[[1], [1, 1], [1, 2, 1], [1, 3, 3, 1], [1, 4, 6, 4, 1], [1, 5, 10, 10, 5, 1], [1, 6, 15, 20, 15, 6, 1]]\n"
     ]
    }
   ],
   "source": [
    "for i in range(8):\n",
    "    print(s.generate(i))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
